package com.haoqizhe.kernel.shiro.properties;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Primary;

import java.util.List;

/**
 * shiro 配置文件
 *
 * @author haoqizhe.li
 * @date 2018/7/4
 **/
@Data
@ConfigurationProperties(prefix = "shiro")
@Primary
public class ShiroProperties {

    /**
     * 无需认证的url
     */
    private List<String> anon;

    /**
     * 退出登陆url
     */
    private String logout;

    /**
     * 需要认证的url
     */
    private List<String> authc;

    /**
     * 登陆url
     */
    private String loginUrl;

    private String successUrl;

    /**
     * 未授权请求url
     */
    private String unauthorizedUrl;

    private Boolean singleLogin;

    private RedisProperties redis = new RedisProperties();

    public ShiroProperties() {
        this.singleLogin = true;
        this.logout = "/logout";
        this.loginUrl = "/notLogin";
        this.unauthorizedUrl = "/unauthorized";
    }

    @Data
    public class RedisProperties {
        private String tokenPrefix;
        private String userPrefix;
        private String rolePrefix;
        private String permissionsPrefix;

        public RedisProperties() {
            this.tokenPrefix = "shiro:token:";
            this.userPrefix = "shiro:user:";
            this.rolePrefix = "shiro:user:%s:role";
            this.permissionsPrefix = "shiro:user:%s:permissions";
        }
    }

}
